<template>
  <el-main v-loading="loading">
    <el-row>
      <el-col :span="15">
        <report-detail-table
            :report="form"
        ></report-detail-table>
      </el-col>
      <report-comment-area
          :evaluation-data="evaluationData"
      >

      </report-comment-area>
    </el-row>
  </el-main>
</template>

<script>
import ReportCommentArea from "@/components/new/report-comment/report-comment-area/ReportCommentArea";
import ReportDetailTable from "@/components/new/report-detail-table/ReportDetailTable";
import {getCollaborationTaskReport, getReportEvaluationByReportID, getScreenshot} from "@/api/report";
export default {
  name: "CollaborationTaskReportDetail",
  components: {ReportDetailTable, ReportCommentArea},
  props: {
    reportId: undefined
  },
  data(){
    return {
      evaluationData: {},
      loading: false,
      // 报告信息
      form: {
        id: -1,
        taskname: '',
        type: '',
        environment: '',
        description: '',
        steps: '',
        screenshot: 'https://lluviasnowb01.oss-cn-hangzhou.aliyuncs.com/collect/'
      },
    }
  },
  mounted() {
    this.loadAll();
  },
  methods: {
    async getEvaluationForm() {
      this.evaluationData = await getReportEvaluationByReportID(this.reportid, sessionStorage.getItem('userid'));
    },

    async getReport() {
      this.loading = true;
      const reportid = this.reportId;
      const res = await getCollaborationTaskReport(reportid);
      if (res.code !== 200) {
        return this.$message.error(res.msg);
      }

      const obj = res.data;
      const reportId = obj.id;

      // this.form["screenshot"]=this.baseUrl
      for (let key of Object.keys(obj)) {
        if(key==='id')
          sessionStorage.setItem('report_boss_evaluate_id',obj['id']);
        if (key === 'type') {
          if (obj['type'] === 'function_test') this.form['type'] = '功能测试';
          else if (obj['type'] === 'performance_test') this.form['type'] = '性能测试';
          else if (obj['type'] === 'bug_explore') this.form['type'] = 'Bug探索';
        } else {
          this.form[key] = obj[key];
        }
      }
      getScreenshot(reportId).then(res2 => {
        this.form["screenshot"] = this.baseUrl + res2[0].url
      });

      this.loading = false;
    },
    loadAll(){
      if(this.reportId !== undefined){
        console.log('load')
        this.getReport();
        this.getEvaluationForm();
      }
    }
  },
  watch: {
    reportId(newVal){
      this.loadAll()
    }
  }
}
</script>

<style scoped>

</style>
